/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.dusa.worklog.viewer;

import java.awt.Component;
import java.sql.Time;
import java.text.DateFormat;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author vdusa
 */
public class TimeCellRenderer extends DefaultTableCellRenderer {
    private DateFormat format;

    public TimeCellRenderer(DateFormat format){
        this.format=format;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if (value instanceof Time) {
            java.sql.Time sql_d = (Time)value;
            java.util.Date d = new java.util.Date(sql_d.getTime());

            String strTime = format.format(d);
            this.setText(strTime);
        }

        return this;
    }
}

